package org.example.util.file;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * @author: ZhangMingmin
 * @since: 2025-03-24 21:05
 * @description:
 */
@Slf4j
public class TxtDetailUtil {

    public static final String FILE_EXTENSION_TXT = "txt";
    
    /**
     * 读取txt文本
     * 
     * @param fis fis
     * @param fileName fileName
     * @return return
     * @throws Exception
     */
    public static String parseTxtFile(InputStream fis, String fileName) throws Exception{
        StringBuilder content = new StringBuilder();
        try (InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(isr)) {
            String line;
            //逐行读取文件内容
            while ((line = br.readLine()) != null) {
                content.append(line).append("\n");
            }
        }
        return content.toString();
    }
}
